import './index.less';
import './src/assets/icon/iconfont.css';

import './src/tools/Date';
import throttle from './src/tools/throttle';
import debounce from './src/tools/debounce';
import heart from './src/tools/heart';
import $http from './src/api/index'
import app from './App';

Message.success = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "success",
            message: value
        });
    }

    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "success",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
Message.warning = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "warning",
            message: value
        });
    }
    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "warning",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
Message.info = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "info",
            message: value
        });
    }
    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "info",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
Message.error = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "error",
            message: value
        });
    }
    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "error",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
export function Message(options) {
    app.Message(options);
}

export let Loading = {
    service(options) {
        return app.Loading(options)
    }
}

export function Upload(options) {
    app.Upload(options)
}
 // 显示滚动
export function HtmlVisibleScroll() {
    let html = document.getElementsByTagName('html')[0];
    let body = document.body;
    html.style.overflow = "visible";
    body.style.overflow = "visible";
}
// 禁止滚动
export function HtmlHiddenScroll() {
    let html = document.getElementsByTagName('html')[0];
    let body = document.body;
    html.style.overflow = "hidden";
    body.style.overflow = "hidden";
}
/* module.exports = {
    Upload: Upload,
    Loading: Loading,
    Message: Message,
} */

export function Confirm(title,message,options) {
   return app.Confirm(title,message,options);
} 

export function PreviewImage(url,options) {
    return app.PreviewImage(url,options);
}

const flag = process.env.NODE_ENV == 'production';

// rewirteLog();
export default {
    Upload: Upload,
    Loading: Loading,
    Message: Message,
    HtmlHiddenScroll,
    HtmlVisibleScroll,
    throttle,
    debounce,
    $http,
    PreviewImage,
    Confirm,
    heart,
    install(Vue) {
        // vue2
        if (typeof Vue == 'function') {
            Vue.prototype.$msg = Message;
            Vue.prototype.$loading = Loading;
            Vue.prototype.$upload = Upload;
            Vue.prototype.$http = $http;
            // 显示滚动
            Vue.prototype.HtmlVisibleScroll = HtmlVisibleScroll;

            // 禁止滚动
            Vue.prototype.HtmlHiddenScroll = HtmlHiddenScroll;
        }
        // vue3
        if (typeof Vue == 'object') {
            /*  
                使用
                const { proxy } = getCurrentInstance();
                const { $msg, $loading, $upload } = proxy;
            */
            Vue.config.globalProperties.$msg = Message;
            Vue.config.globalProperties.$loading = Loading;
            Vue.config.globalProperties.$upload = Upload;
            Vue.config.globalProperties.$http = $http;

            // 显示滚动
            Vue.config.globalProperties.HtmlVisibleScroll = HtmlVisibleScroll;

            // 禁止滚动
            Vue.config.globalProperties.HtmlHiddenScroll = HtmlHiddenScroll;
        }
    }
}


